package com.lst.api.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lst.api.constant.BusinessLicenseStatusEnum;
import com.lst.api.entity.CompanyInfo;
import com.lst.api.exception.RequestParamErrorException;
import com.lst.tools.basics.utils.DateUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 公司信息
 *
 * @author Frank
 * @date 2019-12-30 10:31:37
 * @version: V1.0
 */
@Data
@NoArgsConstructor
public class CompanyInfoVo implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "companyName", value = "公司名称", required = true, dataType = "String")
    private String companyName;

    @ApiModelProperty(name = "companyTypeId", value = "公司类型", required = true, dataType = "Long")
    private Long companyTypeId;

    @ApiModelProperty(name = "companyTypeOther", value = "公司其他类型", dataType = "String")
    private String companyTypeOther;

    @ApiModelProperty(name = "businessPlaceId", value = "经营场所id", required = true, dataType = "Long")
    private Long businessPlaceId;

    @ApiModelProperty(name = "businessPlaceRent", value = "经营场租金", dataType = "Double")
    private Double businessPlaceRent;

    @ApiModelProperty(name = "businessLicenseStatus", value = "营业执照   0:无   1:有", required = true, dataType = "String")
    private String businessLicenseStatus;

    @ApiModelProperty(name = "establishAt", value = "成立日期", required = true, dataType = "Date")
    @JsonFormat(pattern = DateUtils.DATE_FORMAT_1)
    private Date establishAt;

    @ApiModelProperty(name = "industryTypeId", value = "单位类型", required = true, dataType = "Long")
    private Long industryTypeId;

    @ApiModelProperty(name = "monthTurnoverAmount", value = "月营业额，单位元", required = true, dataType = "Double")
    private Double monthTurnoverAmount;

    @ApiModelProperty(name = "annualTaxAmount", value = "年纳税，单位元", required = true, dataType = "Double")
    private Double annualTaxAmount;

    @ApiModelProperty(name = "annualInvoiceAmount", value = "年开票额，单位元", required = true, dataType = "String")
    private Double annualInvoiceAmount;

    public CompanyInfoVo(CompanyInfo companyInfo) {
        if (companyInfo == null) {
            return;
        }
        this.companyName = companyInfo.getCompanyName();
        this.companyTypeId = companyInfo.getCompanyTypeId();
        this.companyTypeOther = companyInfo.getCompanyTypeOther();
        this.businessPlaceId = companyInfo.getBusinessPlaceId();
        this.businessPlaceRent = companyInfo.getBusinessPlaceRent();
        this.businessLicenseStatus = companyInfo.getBusinessLicenseStatus();
        this.establishAt = companyInfo.getEstablishAt();
        this.industryTypeId = companyInfo.getIndustryTypeId();
        this.monthTurnoverAmount = companyInfo.getMonthTurnoverAmount();
        this.annualTaxAmount = companyInfo.getAnnualTaxAmount();
        this.annualInvoiceAmount = companyInfo.getAnnualInvoiceAmount();
    }

    public void check() {
        boolean check = StringUtils.isNotBlank(this.companyName)
                && this.companyTypeId != null
                && this.businessPlaceId != null
                && BusinessLicenseStatusEnum.getByKey(this.businessLicenseStatus) != null
                && this.establishAt != null
                && this.industryTypeId != null
                && this.monthTurnoverAmount != null
                && this.annualTaxAmount != null
                && this.annualInvoiceAmount != null;
        if (!check) {
            throw new RequestParamErrorException("CompanyInfoVo请求参数不合法！");
        }
    }

    public boolean isAllFieldNull() {
        return StringUtils.isBlank(this.companyName)
                && this.companyTypeId == null
                && this.businessPlaceId == null
                && BusinessLicenseStatusEnum.getByKey(this.businessLicenseStatus) == null
                && this.establishAt == null
                && this.industryTypeId == null
                && this.monthTurnoverAmount == null
                && this.annualTaxAmount == null
                && this.annualInvoiceAmount == null;
    }

}